package com.longsunhd.yum.buffalo.network.action;

import android.os.Handler;
import android.os.Message;

import com.longsunhd.yum.buffalo.base.BaseApplication;
import com.longsunhd.yum.buffalo.bean.BaffaloDetailBean;
import com.longsunhd.yum.buffalo.network.Network;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.functions.Consumer;
import io.reactivex.schedulers.Schedulers;

/**
 * 作者：黄宣淇
 * 时间：2021/5/10 0010
 * 如何代码没有备注，一个月后，只有你和上帝知道--鲁迅
 */
public class BaffaloApiUtils {
    private Message message=new Message();
    static BaffaloApiUtils instance;
    public static BaffaloApiUtils newInstance(){

        instance = new BaffaloApiUtils();

        return instance;
    }

    public  void getBuffalo(String token,String electron_label,final Handler handler){
        Network.getBuffaloApi(token)
                .getBuffaloDetail(electron_label)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<BaffaloDetailBean>() {
                    @Override
                    public void accept(final BaffaloDetailBean loginBean) throws Exception {
                        if(loginBean!=null){
                            message.obj=loginBean;
                            handler.sendMessage(message);
                        }else {
                            BaseApplication.showToast("获取牛详情信息失败");
                        }
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        throwable.getMessage();
                        BaseApplication.showToast("获取牛详情信息失败");
                    }
                });
    }
}
